//
//  UIBarButtonItem+add.m
//  tabBarText
//
//  Created by tsb1119 on 2017/1/5.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "UIBarButtonItem+add.h"
@implementation UIBarButtonItem (add)

+(UIBarButtonItem *)itemWithImage:(NSString *)image ImageHighLight:(NSString *)imageHighLight Target:(id)target Seletor:(SEL)seletor CGRect:(CGRect)rect
{
    UIButton * btn =[[UIButton alloc]initWithFrame:rect];
    [btn setImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:imageHighLight] forState:UIControlStateHighlighted];
    
    [btn addTarget:target action:seletor forControlEvents:UIControlEventTouchUpInside];
    
    UIView *btnView = [[UIView alloc]initWithFrame:btn.bounds];
    [btnView addSubview:btn];
    UIBarButtonItem * barButtonItem =[[UIBarButtonItem alloc]initWithCustomView:btnView];
    return barButtonItem;
}

+(UIBarButtonItem *)itemWithTitle:(NSString *)title Target:(id)target Seletor:(SEL)seletor
{
    
    UIButton * btn =[[UIButton alloc]init];
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    CGSize btnSize = [btn intrinsicContentSize];
    btn.frame = CGRectMake(0, 0, btnSize.width+10, btnSize.height+10);
    [btn addTarget:target action:seletor forControlEvents:UIControlEventTouchUpInside];
    [btn.titleLabel setFont:[UIFont systemFontOfSize:16]];
    UIView *btnView = [[UIView alloc]initWithFrame:btn.bounds];
    //将按钮向左侧移动
//    [btn setContentEdgeInsets:UIEdgeInsetsMake(0, 0, 0, -15)];
    [btnView addSubview:btn];
    UIBarButtonItem * barButtonItem =[[UIBarButtonItem alloc]initWithCustomView:btnView];
    return barButtonItem;
}

+(UIBarButtonItem *)itemWithTitle:(NSString *)title backgroundColor:(UIColor*)backgroundColor Target:(id)target Seletor:(SEL)seletor
{
    UIButton * btn =[[UIButton alloc]initWithFrame:CGRectMake(0, 0, 50, 30)];
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btn addTarget:target action:seletor forControlEvents:UIControlEventTouchUpInside];
    [btn.titleLabel setFont:[UIFont systemFontOfSize:16]];
    [btn setBackgroundColor:backgroundColor];
    btn.layer.cornerRadius = 15;
    btn.clipsToBounds = YES;
    UIView *btnView = [[UIView alloc]initWithFrame:btn.bounds];
    
    [btnView addSubview:btn];
    UIBarButtonItem * barButtonItem =[[UIBarButtonItem alloc]initWithCustomView:btnView];
    return barButtonItem;
}
@end
